<?php

use think\migration\Migrator;
use think\migration\db\Column;

class TopicUserDaySync extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('topic_user_day_sync', ['comment' => '每日做题记录同步时同一个用户只保留最大分值']);
        $table
            ->addColumn('user_id', 'integer', array('limit' => 30, 'default' => 0, 'comment' => '练习人'))
            ->addColumn('unit_id', 'integer', array('limit' => 30, 'default' => 0, 'comment' => '所属单位'))
            ->addColumn('date_of', 'string', array('limit' => 220, 'null' => true, 'comment' => '日期'))
            ->addColumn('correct', 'string', array('limit' => 120, 'null' => true, 'comment' => '答对的题目数量'))
            ->addColumn('error', 'string', array('limit' => 220, 'null' => true, 'comment' => '答错的题目数量'))
            ->addColumn('correct_rate', 'string', array('limit' => 120, 'null' => true, 'comment' => '正确率'))
            ->addColumn('duration', 'string', array('limit' => 220, 'null' => true, 'comment' => '答题时长'))
            ->addColumn('total_seconds', 'integer', array('limit' => 30, 'default' => 0, 'comment' => '总秒数(时长转换)'))
            ->addColumn('score', 'string', array('limit' => 50, 'null' => true, 'comment' => '得分'))
            ->addColumn('status', 'boolean',array('limit' => 1, 'default' => 1, 'comment' => '状态(1or2,待审or已审)'))
            ->addColumn('is_admin', 'boolean',array('limit' => 1, 'default' => 0, 'comment' => '是否为管理员(0or1,否or是)'))
            ->addTimestamps()
            ->addSoftDelete()
            ->create();


        $table = $this->table('topic_user_day', ['comment' => '每日做题记录']);
        $table
            ->addColumn('is_sync', 'boolean',array('limit' => 1, 'default' => 0, 'comment' => '状态(0or1,待同步or已同步)'))
            ->save();


        $table = $this->table('topic_user_day_sync', ['comment' => '每日做题记录']);
        $table
            ->addColumn('topic_user_day_id', 'integer', array('limit' => 30, 'default' => 0, 'comment' => '同步的id'))
            ->save();
    }
}
